function [var2d mask batim] = get_var(s_cfg, s_at, bl_corner, tr_corner, ...
                        m_bl_corner, m_tr_corner,...
                        bat_bl_corner, bat_tr_corner)
%function var2d = get_var(s_cfg, s_at, bl_corner, tr_corner, ...
%                       m_bl_corner, m_tr_corner,...
%                       bat_bl_corner, bat_tr_corner)
%
% Extracts the MOHID netcdf data with the landmask
%

    switch (s_cfg.filetype)
        
        case 'mat'
            var2d = getmat(s_cfg.matfile, ...
                    s_at.varname, ...
                    m_bl_corner, ...
                    m_tr_corner, ...
                    1 ...  %stride
                    );
            mask = getmat(s_cfg.matfile, ...
                    'matmask', ...
                    m_bl_corner, ...
                    m_tr_corner, ...
                    1 ...  %stride
                    );
            batim = getmat(s_cfg.matfile, ...
                    'matbatim', ...
                    bat_bl_corner, ...
                    bat_tr_corner, ...
                    1 ...  %stride
                    );
                
        case 'nc'
            
            start_nc = bl_corner - ones(size(bl_corner));
            count_nc = tr_corner - start_nc;
            var2d = nc_varget(s_cfg.file, ...
                        s_at.varname, ...
                        start_nc,  ... % bl_corner
                        count_nc ...
                    );
                
            m_start_nc = m_bl_corner - ones(size(m_bl_corner));
            m_count_nc = m_tr_corner - m_start_nc;
            mask = nc_varget(s_cfg.file, ...
                        'mask', ...
                        m_start_nc,  ... % bl_corner (tzxy)
                        m_count_nc ...
                    );

            bat_start_nc = bat_bl_corner - ones(size(bat_bl_corner));
            bat_count_nc = bat_tr_corner - bat_start_nc;
            batim = nc_varget(s_cfg.file, ...
                        'bathymetry', ...
                        bat_start_nc,  ... % bl_corner (xy)
                        bat_count_nc ...
                    );

        case 'cdf'
            var2d = getnc(s_cfg.file, ...
                      s_at.varname, ...
                      bl_corner,  ... % bl_corner
                      tr_corner ... %tr_corner
                      );
            mask = getnc(s_cfg.file, ...
                    'mask', ...
                    m_bl_corner,  ... % bl_corner (tzxy)
                    m_tr_corner ... %tr_corner (tzxy)
                    );
            batim = getnc(s_cfg.file, ...
                    'bathymetry', ...
                    bat_bl_corner,  ... % bl_corner (tzxy)
                    bat_tr_corner ... %tr_corner (tzxy)
                    );

        case 'hdf5'
            var2d = gethdf5_2d(s_cfg.file, ...
                    s_at.varname, ...
                    bl_corner, ...
                    tr_corner, ...
                    1 ...  %stride
                    );
            mask = gethdf5_2d(s_cfg.file, ...
                    '/Grid/WaterPoints3D', ...
                    bl_corner, ...
                    tr_corner, ...
                    1 ...  %stride
                    );

            batim = gethdf5_2d(s_cfg.file, ...
                    '/Grid/Bathymetry', ...
                    bat_bl_corner, ...
                    bat_tr_corner, ...
                    1 ...  %stride
                    );

        otherwise
            disp ('Error: wrong filetype defined! mat, cdf or hdf5 only!');
            
    end
    
    nn = find(mask == 0); % Find land
    mask(nn) = NaN; % and NaN it...
    
    %pass the mask out and work with it!
    %var2d = var2d .* mask; % Apply the landmask to our data.    